package sol.leetcode;

/**
 * Implement strStr()
 */
public class Issue028 {
    public int strStr(String haystack, String needle) {
        int m = haystack.length();
        int n = needle.length();
        for (int i = 0; i <= m - n; ++i) {
            int j;
            for (j = 0; j < n; ++j)
                if (haystack.charAt(i + j) != needle.charAt(j))
                    break;
            if (j == n)
                return i;
        }
        return -1;
    }

    public static void main(String[] args) {
        String haystack = "abcaa";
        String needle = "aa";
        Issue028 sol = new Issue028();
        System.out.println(sol.strStr(haystack, needle));
    }
}
